var express = require('express');
var router = express.Router();

// 引入连接池对象
const sql = require('../db/index');
const Response = require('../utils/response');

router.get('/getEvaluationCountsForCourse', async (req, res) => {
  const { courseId } = req.query;
  // console.log(courseId);
  const [course] = await sql.query('SELECT * from course_table WHERE id =?', [courseId])
  // console.log(course);

  const query = `
  SELECT
        SUM(CASE WHEN e.level = '优秀' THEN 1 ELSE 0 END) AS 优秀,
        SUM(CASE WHEN e.level = '良好' THEN 1 ELSE 0 END) AS 良好,
        SUM(CASE WHEN e.level = '一般' THEN 1 ELSE 0 END) AS 一般
  FROM course_evaluation e
  JOIN course_table c ON e.course_id = c.id
  WHERE c.id = ?
  GROUP BY e.course_id;
  `;
  const [level] = await sql.query(query,[courseId])
  console.log(level);
  let levels = level[0]
  console.log(levels);
  
});

module.exports = router;
